package br.ufrgs.ga.model;

import java.security.InvalidParameterException;

/**
 * Any implementation of chromosome must extends this class.
 * @author mineiro
 *
 * @param <T> Chromosome DNA strand type.
 */
public abstract class AbstractChromosome<T> implements IChromosome<T> {

	/**
	 * Chromosome DNA strand.
	 */
	protected T dnaStrand;
	
	protected AbstractChromosome(T dnaStrand) {
		if (!isValid(dnaStrand)) {
			throw new InvalidParameterException("The DNA Strand is not a valid one. A valid DNA strand is a string of integers in the range [0, maxCityIdValue], and this string length must be equals to maxCityIdValue + 1.");
		}
		
		this.dnaStrand = dnaStrand;
	}

	@Override
	public T getDnaStrand() {
		return dnaStrand;
	}

	@Override
	public abstract IChromosome<T> clone() throws CloneNotSupportedException;
	
	/**
	 * String representation of the chromosome
	 */
	@Override
	public String toString() {
		return dnaStrand.toString();
	}
}
